<% if (current_user && current_user.id == @user.id) || current_user.isadmin %>
<h1>Editing User Information</h1>

<%= form_for(@user) do |f| %>
  <% if @user.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

      <ul>
      <% @user.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :first_name %><br />
    <%= f.text_field :first_name %>
  </div>
  <div class="field">
    <%= f.label :last_name %><br />
    <%= f.text_field :last_name %>
  </div>
  <div class="field">
    <%= f.label "E-mail Address" %><br />
    <%= f.text_field :email %>
  </div>
  <div>
    <%= f.label "New Password" %><br />
    <%= f.password_field :password %>
  </div>
  <div>
    <%= f.label "Confirm New Password" %><br />
    <%= f.password_field :password_confirmation %>
  </div>
  <div class="field">
    <%= f.label "Phone Number" %><br />
    <%= f.text_field :phone %>
  </div>
  <div class="field">
    <%= f.label "Address (line 1)" %><br />
    <%= f.text_field :addr1 %>
  </div>
  <div class="field">
    <%= f.label "Address (line 2)" %><br />
    <%= f.text_field :addr2 %>
  </div>
  <div class="field">
    <%= f.label "City" %><br />
    <%= f.text_field :city %>
  </div>
  <div class="field">
    <%= f.label "State" %><br />
    <%= f.text_field :state %>
  </div>
  <div class="field">
    <%= f.label "Zip Code" %><br />
    <%= f.text_field :zip %>
  </div>
  <div class="field">
    <%= f.label "Do you wish to be a driver?" %>
    <%= f.check_box :isdriver %>
  </div>
  <div class="field">
    <%= f.label "Do you wish to be a customer?" %>
    <%= f.check_box :iscustomer %>
  </div>
  <%if current_user.isadmin %>
  <div class="field">
    <%= f.label "Should this user be an Administrator?" %>
    <%= f.check_box :isadmin %>
  </div>
  <div class="field">
    <%= f.label "Should this user be flagged & disabled?" %>
    <%= f.check_box :isflagged %>
  </div>
  <% end %>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>


<%= link_to 'Show', @user %> |
<%= link_to 'Home', root_url %>
<% else %>
<% if current_user %>
<p>Error: you are attempting to edit a user that is not yourself.</p>
<p>Stop being such a jerk</p>
<p>Yes, I called you a jerk.  Go <%= link_to "home", root_url %> and cry about it.</p>
<% else %>
<p>Error: You are not currently logged in.</p>
<p>If you would like to place an order please <%= link_to "log in", log_in_path %>.</p>
<p>If you do not have an account, please <%= link_to "sign up", sign_up_path %></p>
<p>Or you can return to the <%= link_to "home page", root_url %>.</p>
<% end %>
<% end  %>
